<template>
	<uni-popup ref="popup" type="bottom">
		<view class="content column">
			<text class="mix-icon icon-guanbi" @click="close"></text>
			<view class="pro-info row">
				<image class="pic" :src=" '/static/icon/default-avatar.png'" mode="aspectFill"></image>
				<view class="right column">
					<text class="price">{{ gamePlayer.player.name }}</text>
					<text class="stock" @click="makeCall(gamePlayer.player.phone)">联系方式：{{ gamePlayer.player.phone }}</text>
				</view>
			</view>
				<!-- 规格 -->
			<scroll-view class="c-wrap" scroll-y="true">
				<view class="number-wrap row">
					<text class="s-tit fill">成绩</text>
					<input class="input score" v-model="fee" @input="handleInput" type="number" maxlength="20" placeholder-class="placeholder">
					<!-- <mix-number-box :value="gamePlayer.score" :min="0" :max="1000000" @eventChange="onNumberChange"></mix-number-box> -->
					<text class="unit">{{game.scoreTypeTxt}}</text>
				</view>
			</scroll-view>
			<view class="btn-wrap row">
				<view class="confirm-btn center" @click="confirm()">
					<text>提交</text>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import {getUnique} from '@/common/js/util'
	export default {
		data() {
			return {
				type: '', //cart加入购物车 buy立即购买
				specList: [], //规格
				skuList: [],
				currentSku: {},
				fee: 0,
				fee_bak: 0,
			}
		},
		props: {
			gamePlayer: {
				type: Object,
				default(){
					return {}
				}
			},
			game: {
				type: Object,
				default(){
					return {}
				}
			}
		},
		watch: {
			gamePlayer(gamePlayer){
				this.gamePlayer = gamePlayer;
				this.fee = gamePlayer.scoreStr;
				this.fee_bak = gamePlayer.scoreStr;
				console.log("=watch=gamePlayer=="+JSON.stringify(gamePlayer))
			},
				
		},
		methods: {
			handleInput(e) {
				console.log("handleInput"+JSON.stringify(e))
				let val = e.target.value;
				if(!/^[0-9,.]*$/.test(val)){
				  this.$util.msg("请输入正确的赛事成绩");
				}else{
					this.fee_bak = val;
				}
				// val = val.replace(/^./g, "");
				// val = val.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
				// val = val.replace(/.{2,}/g, "."); //只保留第一个. 清除多余的
				// val = val.replace(/^0+./g, "0.");
				// val = val.match(/^0+[1-9]+/) ? (val = val.replace(/^0+/g, "")) : val;
				// val = val.match(/^\d*(.?\d{0,2})/g)[0] || "";
				// val = val.replace(".", "").replace(/./g, "").replace("", ".");
				this.fee = val;
				
			},
			//结算
			confirm(){
				// console.log("==onSubmitPlayerScore=="+JSON.stringify(this.player))
				if(!/^[0-9,.]*$/.test(this.fee)){
				  this.$util.msg("请输入正确的赛事成绩");
				  return ;
				}else{
					this.gamePlayer.scoreStr = this.fee;
					this.$emit("onSubmitPlayerScore", this.gamePlayer);
				}
			},
			//选择规格值
			chooseAttr(item, parent){
				if(item.checked){
					return;
				}
				parent.attrList.forEach(attr=>{
					if(attr.name !== item.name){
						attr.checked = false;
					}
				})
				item.checked = true;
				this.renderChecked();
			},
			//处理选中值
			renderChecked(){
				const {
					specList,
					skuList,
					score
				} = this;
				const attrs = specList.map(item=> item.attrList.filter(attr=> attr.checked)[0].name).join(' ');
				this.currentSku = skuList.filter(item=> item.name === attrs)[0];
				
				this.$emit('setSku', {
					...this.currentSku
				});
			},
			//修改数量
			onNumberChange(e){
				this.gamePlayer.score = e.number;
				// this.$emit('refresh', {
				// 	...this.player
				// });
			},
			open(type){
				this.type = typeof type === 'string' ? type: '';
				this.$refs.popup.open();
			},
			close(){
				this.$refs.popup.close();
			},
			makeCall(phoneNumber){
				uni.makePhoneCall({
					phoneNumber: phoneNumber
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content{
		width: 750rpx;
		background-color: #fff;
		border-radius: 10rpx 10rpx 0 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom); 
		position: relative;
	}
	.icon-guanbi{
		position: absolute;
		right: 10rpx;
		top: 10rpx;
		padding: 20rpx;
		font-size: 32rpx;
		color: #999;
	}
	.pro-info{
		padding: 30rpx 32rpx 16rpx;
		
		.pic{
			flex-shrink: 0;
			width: 160rpx;
			height: 160rpx;
			margin-right: 20rpx;
			background-color: #f7f7f7;
			border-radius: 10rpx;
		}
		.price{
			padding-top: 10rpx;
			margin-bottom: 26rpx;
			font-size: 34rpx;
			color: $base-color;
			font-weight: 700;
		}
		.stock{
			margin-bottom: 20rpx;
			font-size: 24rpx;
			color: #999;
		}
		.attr-wrap{
			flex-wrap: wrap;
			
			text{
				line-height: 1.4;
				font-size: 24rpx;
				color: #333;
			}
			.attr{
				flex-shrink: 0;
				margin-right: 10rpx;
				color: #999;
				
				&.checked{
					color: #333;
				}
			}
		}
	}
	.s-tit{
		margin-left: 42rpx;
		font-size: 30rpx;
		color: #333;
		font-weight: 700;
		line-height: 90rpx;
	}
	.unit{
		margin-left: 42rpx;
		font-size: 30rpx;
		color: #333;
		font-weight: 700;
		line-height: 90rpx;
	}
	.c-wrap{
		min-height: 20vh;
		max-height: 60vh;
	}
	.sku-list{
		.attrs{
			display: flex;
			flex-wrap: wrap;
			padding-left: 32rpx;
			padding-right: 20rpx;
		}
		.attr{
			min-width: 58rpx;
			height: 58rpx;
			padding: 0 24rpx;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			font-size: 26rpx;
			color: #333;
			
			&:after{
				border-color: #e0e0e0;
			}
			&.active{
				color: $base-color;
				background-color: rgba(255, 82, 111, .03);
			
				&:after{
					border-color: rgba(255, 82, 111, .5);
				}
			}
			&.disabled{
				background-color: #ddd;
			}
		}
	}
	.number-wrap{
		padding-right: 40rpx;
	}
	.btn-wrap{
		align-items: flex-end;
		justify-content: center;
		padding: 36rpx 0 30rpx;
	}
	.confirm-btn{
		width: 670rpx;
		height: 84rpx;
		background-color: $base-color;
		font-size: 32rpx;
		color: #fff;
		border-radius: 100rpx;
	}
	.sm{
		width: 670rpx;
		margin: 0 auto;
		
		.btn{
			flex: 1;
			height: 84rpx;
			font-size: 32rpx;
			color: #fff;
			background-color: orange;
			border-radius: 100rpx 0 0 100rpx;
			
			&:last-child{
				background-color: $base-color;
				border-radius: 0 100rpx 100rpx 0;
			}
		}
	}
	.score{
		border-bottom: 1px solid #878787;
		width: 200rpx;
		line-height: 50rpx;
		text-align: center;
	}
</style>
